﻿using System;
using System.Collections;
using System.Drawing;

namespace TextEditor
{
    
    /// <summary>
    /// 文本对齐方式
    /// </summary>
    public class ParagraphTagProvider : SmartTagProvider
    {
        public override void GetCommands(ArrayList myList)
        {
            ZYTextParagraph currentElement = base.OwnerDocument.Content.CurrentElement as ZYTextParagraph;
            if (currentElement != null)
            {
                myList.Add(new SmartTagItem(this, 2, currentElement.LeftAlign, "左对齐"));
                myList.Add(new SmartTagItem(this, 3, currentElement.CenterAlign, "居中对齐"));
                myList.Add(new SmartTagItem(this, 4, currentElement.RightAlign, "右对齐"));
                myList.Add(new SmartTagItem(this, 5, currentElement.JustifyAlign, "两边对齐"));
            }
        }

        public override Point GetPos()
        {
            if (base.OwnerControl.PageViewMode)
            {
                return new Point(-base.OwnerControl.SmartTagSize() - 13, base.Element.Bounds.Bottom - base.Element.Bounds.Height);
            }
            return base.GetPos();
        }

        public override bool HandleCommand(SmartTagItem item)
        {
            ZYTextParagraph currentElement = base.OwnerDocument.Content.CurrentElement as ZYTextParagraph;
            if (currentElement != null)
            {
                switch (item.ID)
                {
                    case 2:
                        base.OwnerDocument.BeginContentChangeLog();
                        currentElement.LeftAlign = true;
                        base.OwnerDocument.EndContentChangeLog();
                        base.OwnerDocument.RefreshLine();
                        base.OwnerDocument.UpdateView();
                        return true;

                    case 3:
                        base.OwnerDocument.BeginContentChangeLog();
                        currentElement.CenterAlign = true;
                        base.OwnerDocument.EndContentChangeLog();
                        base.OwnerDocument.RefreshLine();
                        base.OwnerDocument.UpdateView();
                        return true;

                    case 4:
                        base.OwnerDocument.BeginContentChangeLog();
                        currentElement.RightAlign = true;
                        base.OwnerDocument.EndContentChangeLog();
                        base.OwnerDocument.RefreshLine();
                        base.OwnerDocument.UpdateView();
                        return true;

                    case 5:
                        base.OwnerDocument.BeginContentChangeLog();
                        currentElement.JustifyAlign = true;
                        base.OwnerDocument.EndContentChangeLog();
                        base.OwnerDocument.RefreshLine();
                        base.OwnerDocument.UpdateView();
                        return true;
                }
            }
            return false;
        }

        public override bool isEnable()
        {
            return ((base.OwnerDocument.Content.SelectLength == 0) && (base.OwnerDocument.Content.CurrentElement is ZYTextParagraph));
        }

        public override int ImageIndex
        {
            get
            {
                return 0x11;
            }
        }
    }
}

